package com.tao.content.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tao.content.domain.dto.CourseTeacherDto;
import com.tao.content.domain.pojo.CourseTeacher;
import com.tao.content.mapper.CourseTeacherMapper;
import com.tao.content.service.ICourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 服务实现类
 * </p>
 *
 * @author taohongrun
 * @since 2024-11-01
 */
@Service
@Validated
@Slf4j
public class CourseTeacherServiceImpl extends ServiceImpl<CourseTeacherMapper, CourseTeacher> implements ICourseTeacherService {

    @Override
    public CourseTeacher saveCourseTeacher(CourseTeacherDto courseTeacherDto){
        CourseTeacher courseTeacher = new CourseTeacher();
        BeanUtils.copyProperties(courseTeacherDto,courseTeacher);
        save(courseTeacher);
        log.info("成功添加课程教师:{}",courseTeacher);
        return getById(courseTeacher.getId());
    }

    @Override

    public List<CourseTeacher> getCourseTeacher(Long courseId){
        return lambdaQuery().eq(CourseTeacher::getCourseId,courseId).list();
    }
    @Override

    public CourseTeacher updateCourseTeacher(CourseTeacher courseTeacher){
        updateById(courseTeacher);
        log.info("成功修改为:{}",courseTeacher);
        return getById(courseTeacher.getId());
    }
    @Override

    public void removeCourseTeacher(Long courseId,Long teacherId){
        lambdaUpdate()
                .eq(CourseTeacher::getCourseId,courseId)
                .eq(CourseTeacher::getId,teacherId)
                .remove();
        log.info("成功删除id为:{}课程id为:{}的数据",courseId,teacherId);
    }
}
